<template>
    <el-container class="container-class">
        <el-header>
            <div>
                <span>电商后台管理系统</span>
            </div>
            <el-button type="info" @click="logout">退出</el-button>
        </el-header>
        <el-container>
            <el-aside :width="isCollapse ? '64px' : '180px' ">
                <div class="toggle-button" @click="toggleCollapse">
                    <icon class="el-icon-s-operation"></icon>
                </div>
                <el-menu background-color="#333744" text-color="#fff" active-text-color="#409EFF" unique-opened
                         :collapse="isCollapse" :collapse-transition="false" router>
                    <el-menu-item index="/Welcome">
                        <i class="el-icon-menu"></i>
                        <span slot="title">首页</span>
                    </el-menu-item>
                    <el-submenu :index="Item.menuId" v-for="Item in menuList">
                        <template slot="title">
                            <i :class="Item.menuIcon"></i>
                            <span>{{Item.menuTitle}}</span>
                        </template>
                        <submenu>
                            <el-menu-item v-for="SubItem in Item.childrenMenu" :index="SubItem.childrenMenuPath" @click="breadChange(Item.menuTitle,SubItem.childrenMenuTitle)">
                                <i :class="SubItem.childrenMenuIcon"></i>
                                <span slot="title">{{SubItem.childrenMenuTitle}}</span>
                            </el-menu-item>
                        </submenu>
                    </el-submenu>
                </el-menu>
            </el-aside>
            <el-main>
                <el-breadcrumb separator-class="el-icon-arrow-right" v-for="item in $route.matched" :key="item.path">
                    <el-breadcrumb-item :to="{ path: '/Welcome' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>{{item.name}}</el-breadcrumb-item>
                </el-breadcrumb>
                <div style="margin-top: 20px">
                    <el-card class="box-card">
                        <router-view/>
                    </el-card>
                </div>
            </el-main>
        </el-container>
    </el-container>
</template>

<script>
    export default {
        name: 'Home',
        data() {
            return {
                // 是否折叠
                isCollapse: false,
                menuList: [
                    {
                        'menuTitle': '系统管理',
                        'menuIcon': 'el-icon-menu',
                        'menuId':Math.random(),

                        'childrenMenu':[
                            {
                                'childrenMenuTitle': '菜单管理',
                                'childrenMenuPath': '/Menu',
                                'childrenMenuIcon': 'el-icon-menu'
                            },
                            {
                                'childrenMenuTitle': '角色管理',
                                'childrenMenuPath': '/Role',
                                'childrenMenuIcon': 'el-icon-menu'
                            }
                        ],
                    },
                    {
                        'menuTitle': '个人管理',
                        'menuIcon': 'el-icon-menu',
                        'menuId':Math.random(),
                        'childrenMenu':[
                            {
                                'childrenMenuTitle': '44',
                                'childrenMenuPath': '/Welcome',
                                'childrenMenuIcon': 'el-icon-menu'
                            },
                            {
                                'childrenMenuTitle': '55',
                                'childrenMenuPath': '/Welcome',
                                'childrenMenuIcon': 'el-icon-menu'
                            }
                        ],
                    },
                ],
                //面包屑
                menuTitle:'',
                subMenuTitle:'',
            }
        },
        methods: {
            // 点击按钮，切换菜单的折叠与展开
            toggleCollapse() {
                this.isCollapse = !this.isCollapse
            },
            //面包屑
            breadChange(menuTitle,subMenuTitle){
                console.log(menuTitle+"  "+subMenuTitle)
                this.menuTitle = menuTitle;
                this.subMenuTitle = subMenuTitle;
            }
        }
    };
</script>

<style lang="less" scoped>
    .container-class {
        height: 100%;
    }

    .el-header {

        background-color: #373d41;
        display: flex;
        justify-content: space-between;
        padding-left: 0;
        align-items: center;
        color: #fff;
        font-size: 20px;
        > div {
            display: flex;
            align-items: center;
            span {
                margin-left: 15px;
            }
        }
    }

    .el-aside {
        background-color: #333744;
        height: 100%;
        .el-menu {
            border-right: none;
        }
    }

    .el-main {
        background-color: #eaedf1;
    }

    .iconfont {
        margin-right: 10px;
    }

    .toggle-button {
        background-color: #4a5064;
        font-size: 10px;
        line-height: 24px;
        color: #fff;
        text-align: center;
        letter-spacing: 0.2em;
        cursor: pointer;
    }
</style>
